
package com.limoilux.cobolux.ui.editor;

import org.eclipse.jface.text.MarginPainter;
import org.eclipse.jface.text.PaintManager;
import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.jface.text.source.IVerticalRuler;
import org.eclipse.jface.text.source.SourceViewerConfiguration;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.editors.text.TextEditor;

import com.limoilux.cobolux.ui.CoboluxUiUtils;

public class CobolEditor extends TextEditor
{
	public static final RGB COLOR_DEFAULT = new RGB(0, 0, 0);
	public static final RGB COLOR_STRING = new RGB(0, 0, 200);
	public static final RGB COLOR_COMMENT = new RGB(0, 139, 0);
	public static final RGB COLOR_RESERVED = new RGB(139, 58, 98);
	public static final RGB COLOR_FIGURATIVE = new RGB(139, 58, 98);
	public static final RGB COLOR_REGISTER = new RGB(139, 58, 98);

	private static final int LEFT_BORDER = 7;
	private static final int RIGHT_BORDER = 72;

	public CobolEditor()
	{
		super();
	}

	@Override
	protected void initializeEditor()
	{
		super.initializeEditor();

		SourceViewerConfiguration viewerConf = new CobolSourceViewerConfig();

		this.setSourceViewerConfiguration(viewerConf);

		// TODO Faire marché
		this.installTabsToSpacesConverter();

	}

	@Override
	protected ISourceViewer createSourceViewer(Composite parent, IVerticalRuler ruler, int styles)
	{
		return super.createSourceViewer(parent, ruler, styles);
	}

	@Override
	public void createPartControl(Composite parent)
	{
		super.createPartControl(parent);

		MarginPainter mp = null;
		Display display = CoboluxUiUtils.getDisplay();
		ISourceViewer sw = this.getSourceViewer();
		PaintManager pm = new PaintManager(sw);
		Color c = new Color(display, 200, 200, 200);

		// TODO améliorer la méthodes
		mp = new MarginPainter(sw);

		mp.setMarginRulerColumn(CobolEditor.LEFT_BORDER);
		mp.setMarginRulerColor(c);
		mp.setMarginRulerWidth(1);
		pm.addPainter(mp);

		mp = new MarginPainter(sw);
		mp.setMarginRulerColumn(CobolEditor.RIGHT_BORDER);
		mp.setMarginRulerColor(c);
		mp.setMarginRulerWidth(1);

		pm.addPainter(mp);
	}
}
